package cn.kgc.springday03.entity;

import org.springframework.beans.factory.FactoryBean;

import java.sql.Connection;
import java.sql.DriverManager;

/**
 * @Author: 课工场
 * @Version: v1.0  2023/6/14
 * @Description: 获取连接对象的工厂bean  该类可以生产连接对象
 */
public class ConnectionFactoryBean implements FactoryBean<Connection> {

    @Override
    public Connection getObject() throws Exception {

        Class.forName("com.mysql.jdbc.Driver");
        String username = "root";
        String password = "root";
        String url = "jdbc:mysql:///java2320?serverTimezone=UTC";
        Connection connection = DriverManager.getConnection(url, username, password);

        return connection;
    }

    @Override
    public Class<?> getObjectType() {
        return Connection.class;
    }
}
